<script type="text/javascript">
var dateboxFormatter = function(date){
    var y = date.getFullYear();
    var m = date.getMonth()+1;
    var d = date.getDate();
    return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
};


function formatN(value){
    return (value < 10 ? '0' : '') + value;
}

var datetimeParser = function(s) {
    if (!s) {
        return new Date();
    }

    let t = Date.parse(s);
    if (!isNaN(t)){
        return new Date(t);
    } else {
        return new Date(s + ":00:00");
    }
}

var datetimeFormatter = function(date){
    if (!date) {
        return '';
    }

    let tt = [formatN(date.getHours()), formatN(date.getMinutes()), formatN(date.getSeconds())];
    return dateboxFormatter(date) + " " + tt.join(":");
};

var builder = {
    //添加验证信息
    addValidationInfo: function(id, message) {
        this.removeValidationInfo(id);
        // let messageDiv = $("<div id='" + id + "_validationDiv' style='color:red; font-size:12px;'>" + message + "</div>")
        $("#" + id).textbox('textbox').parent().css("border", "1px solid red");
        // $("#" + id).textbox('textbox').parent().after($(messageDiv));
    },

    //移除 验证信息
    removeValidationInfo:function(id) {
        $("#" + id).textbox('textbox').parent().css("border", "");
        $("#" + id + "_validationDiv").remove();
    },

    //提交JSON数据
    postJson: function(url, data, successCallback, failCallback, finalCallback) {
        $.ajax({
            type: "POST",
            url: url,
            data: JSON.stringify(data),
            dataType: "json",
            contentType: "application/json",
            success: function (result) {
                if (successCallback) {
                    successCallback(result);
                }
                if (finalCallback) {
                    finalCallback(result);
                }
            },
            error: function (xmlrequest) {
                console.log(xmlrequest.responseText);
                if (failCallback) {
                    failCallback(xmlrequest);
                }

                if (finalCallback) {
                    finalCallback(xmlrequest);
                }
            }
        });
    },

    removeEmptyField: function(obj) {
        if (obj == null || obj == undefined) {
            return obj;
        }

        let ret = Object.assign({}, obj);

        for (let prop in ret) {
            let val = ret[prop];
            if (val == null || val == undefined || val == '') {
                delete ret[prop];
            }
        }

        return ret;
    },


    removeStrictEmptyField: function(obj) {
        if (obj == null || obj == undefined) {
            return obj;
        }

        let ret = Object.assign({}, obj);

        for (let prop in ret) {
            let val = ret[prop];
            if (val == null || val == undefined || val === '') {
                delete ret[prop];
            }
        }

        return ret;
    }

}

</script>